<?php
class registration extends module {
	public $title = "New registration";
	public $frame = "main";
	
	public function run() {
		$form = new formConstructor($this, "registration", "", _("Registration"));
		$form->addField("login", _("E-mail"), new formString($GLOBALS['userPrimaryProperties']['login']), _('Pleas, enter your e-mail. It will be used as your login'));
		$form->addField(null, _("Register"), new formSubmit());
		
		if ($form->submit()) {
			if (count($form->errors)>0) {
				new pageAlert($this, _("Wrong form filling"));
				$form->write();
			} else {
				if ($this->sql->getValueFromDB("SELECT COUNT(*) FROM users WHERE login='%s'", $form->getValue("login")) == 0) {
					$password = genPass(8);
					new pageAlert($this, _("You are registered. Your password:")." ".$password, PAGE_ALERT_SUCCESS);
					$this->user->registration($form->getValue("login"), $password);
				} else {
					new pageAlert($this, _("The e-mail address is already in use."));
					$form->addError("login");
					$form->write();
				}
			}
		} else {
			$form->write();
		}
	}
}
?>